

import 'package:basic_common/app_theme.dart';
import 'package:basic_common/common_exports.dart';
import 'package:basic_services/serviceDetail/service_detail_controller.dart';
import 'package:basic_widgets/button_widget.dart';
import 'package:basic_widgets/input_widget.dart';

/* 
 * @description: //添加血糖数据
 * @author: Jane 
 * @date: 2023-09-20 15:05:00
 */
class AddSugarDialog extends GetView<ServerDetailController> {
  @override
  Widget build(BuildContext context) {
    return SimpleDialog(
      title:const Align(
        alignment: Alignment.topCenter,
        child: Text("添加血糖"),
      ),
      children: [
        //这边自己定义widget内容
        Center(
          child: Container(
            width: ScreenHelper.screenWidth,
            // margin: const EdgeInsets.symmetric(horizontal: 4),
            padding: EdgeInsets.all(ScreenHelper.width(6)),
            child: ListView(
              shrinkWrap: true,
              children: [
                timeSwitch(),
                buildAddItem(
                    name: "血糖值",
                    unit: "mmol/L",
                    inputController: controller.sugarInputController),
                buildEstimateWidget(),
              ],
            ),
          ),
        ),
        SizedBox(
          height: ScreenHelper.height(15),
        ),
        Container(
          margin: EdgeInsets.symmetric(horizontal: 10),
          child: Row(
            children: [
              Expanded(
                  child: roundBtn(
                      onTap: () {
                        Get.back();
                      },
                      text: "取消",
                      bgColor: Colors.white,
                      textColor: AppTheme.primyColor,
                      borderColor: AppTheme.primyColor)),
              SizedBox(
                width: ScreenHelper.width(10),
              ),
              Expanded(
                  child: roundBtn(
                      onTap: () {
                        Get.back();
                        controller.addSugarData(evaValue: controller.elaInputController.text, checkValue:  controller.sugarInputController.text);
                      },
                      text: "添加",
                      bgColor: AppTheme.primyColor,
                      textColor: Colors.white)),
            ],
          ),
        )
      ],
    );
  }

// 左臂右臂 选择
  Widget timeSwitch() {
    return Column(
      children: [
        Row(
          mainAxisSize: MainAxisSize.min,
          children: [
            SizedBox(
              width: ScreenHelper.width(60),
              child: const Text(
                "检查时间",
                textAlign: TextAlign.left,
                style: TextStyle(color: AppTheme.dartWeakTextColor),
              ),
            ),
            SizedBox(
              width: ScreenHelper.width(10),
            ),
            Expanded(
              child: Padding(
                padding: EdgeInsets.only(right: ScreenHelper.width(30)),
                child: Obx(() => SizedBox(
                      width: ScreenHelper.screenWidth,
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.start,
                        children: [
                          GestureDetector(
                              onTap: () {
                                controller.sugarValue.value = '1';
                              },
                              child: buildGenderCheck(
                                  title: "餐前",
                                  isChecked: controller.sugarValue.value == '1'
                                      ? true
                                      : false)),
                          SizedBox(
                            width: ScreenHelper.width(ScreenHelper.width(5)),
                          ),
                          Expanded(
                            child: GestureDetector(
                                onTap: () {
                                  controller.sugarValue.value = '2';
                                },
                                child: buildGenderCheck(
                                    title: "餐后",
                                    isChecked:
                                        controller.sugarValue.value == '2'
                                            ? true
                                            : false)),
                          ),
                        ],
                      ),
                    )),
              ),
            ),
          ],
        ),
        SizedBox(
          height: ScreenHelper.height(10),
        ),
        Row(
          mainAxisSize: MainAxisSize.min,
          children: [
            SizedBox(
              width: ScreenHelper.width(60),
              child: const Text(
                "",
                textAlign: TextAlign.left,
                style: TextStyle(color: AppTheme.dartWeakTextColor),
              ),
            ),
            SizedBox(
              width: ScreenHelper.width(10),
            ),
            Expanded(
              child: Padding(
                padding: EdgeInsets.only(right: ScreenHelper.width(30)),
                child: Obx(() => SizedBox(
                      width: ScreenHelper.screenWidth,
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.start,
                        children: [
                          GestureDetector(
                              onTap: () {
                                controller.sugarValue.value = '3';
                              },
                              child: buildGenderCheck(
                                  title: "睡前",
                                  isChecked: controller.sugarValue.value == '3'
                                      ? true
                                      : false)),
                          SizedBox(
                            width: ScreenHelper.width(ScreenHelper.width(5)),
                          ),
                          Expanded(
                            child: GestureDetector(
                                onTap: () {
                                  controller.sugarValue.value = '4';
                                },
                                child: buildGenderCheck(
                                    title: "凌晨",
                                    isChecked:
                                        controller.sugarValue.value == '4'
                                            ? true
                                            : false)),
                          ),
                        ],
                      ),
                    )),
              ),
            ),
          ],
        ),
      ],
    );
  }

  /// 评估内容
  Widget buildEstimateWidget() {
    return Row(
      mainAxisSize: MainAxisSize.min,
      children: [
        SizedBox(
          width: ScreenHelper.width(40),
          child: const Text(
            "评估",
            textAlign: TextAlign.left,
            style: TextStyle(color: AppTheme.dartWeakTextColor),
          ),
        ),
        Expanded(
          child: Container(
            alignment: Alignment.topCenter,
            child: mutileTextField(
                hintText: "请输入评估内容",
                textController: controller.elaInputController,
                countNum: "",
                minLines: 2),
          ),
        ),
      ],
    );
  }

  /// item
  Widget buildAddItem(
      {required String name,
      required String unit,
      required TextEditingController inputController}) {
    return SizedBox(
      height: ScreenHelper.height(60),
      child: Row(
        children: [
          SizedBox(
            width: ScreenHelper.width(60),
            child: Text(
              name,
              textAlign: TextAlign.left,
              style: TextStyle(color: AppTheme.dartWeakTextColor),
            ),
          ),
          Expanded(
              child: inputBox(hintText: '', inputController: inputController)),
          SizedBox(
            width: ScreenHelper.width(6),
          ),
          Text(
            '${unit}',
            style: TextStyle(color: AppTheme.dartWeakTextColor),
          ),
        ],
      ),
    );
  }
}
